package com.kuizii.auth.shiro;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.pam.AbstractAuthenticationStrategy;
import org.apache.shiro.authc.pam.AllSuccessfulStrategy;
import org.apache.shiro.realm.Realm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author: nuanyang
 * @Date: 2019/12/10 0010 16:42
 */
public class SingleOneFailStrategy extends AbstractAuthenticationStrategy {
    /**
     * Private class log instance.
     */
    private static final Logger log = LoggerFactory.getLogger(AllSuccessfulStrategy.class);

    @Override
    public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException {


        if (t != null) {
            log.debug("身份验证失败", t.toString());
            if (t instanceof AuthenticationException) {
                //propagate:
                throw ((AuthenticationException) t);
            }
        }
        return singleRealmInfo;
    }
}
